package com.yanqu.road.netty.server;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.channel.ChannelOption;

public class NettyParamOperator {
    public static void buildWebsocketBootstrapOptions(ServerBootstrap serverBootstrap) {
        serverBootstrap.option(ChannelOption.SO_REUSEADDR, true);
        serverBootstrap.option(ChannelOption.SO_RCVBUF, 1024 * 8);
        serverBootstrap.option(ChannelOption.SO_BACKLOG, 128);
        buildSameParam(serverBootstrap);
    }

    public static void buildSslWebsocketBootstrapOptions(ServerBootstrap serverBootstrap) {
        serverBootstrap.option(ChannelOption.SO_REUSEADDR, true);
        serverBootstrap.option(ChannelOption.SO_RCVBUF, 1024 * 64);
        serverBootstrap.option(ChannelOption.SO_BACKLOG, 1024);
        buildSameParam(serverBootstrap);
    }

    public static void buildSameParam(ServerBootstrap serverBootstrap) {
        serverBootstrap.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);

        serverBootstrap.childOption(ChannelOption.SO_KEEPALIVE, true);
        serverBootstrap.childOption(ChannelOption.SO_LINGER, 0);
        serverBootstrap.childOption(ChannelOption.TCP_NODELAY, true);
        serverBootstrap.childOption(ChannelOption.SO_SNDBUF, 1024 * 64);
        serverBootstrap.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
        serverBootstrap.childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 1024 * 128);
        serverBootstrap.childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 1024 * 64);
    }
}
